package com.yisu.expressway.vm_util;

import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.yisu.expressway.R;
import com.yisu.expressway.application.ExApplication;

/**
 * Created by Administrator on 2017/2/6 0006.
 */

public class DBUtils{

    @BindingAdapter({"imageUrl","placeHolder"})
    public static void loadImage(ImageView imageView, String url, Drawable defaultDrawable) {
        if (url == null) {
            imageView.setImageResource(R.drawable.ic_default_home_banner);
        } else {
            Glide.with(ExApplication.getInstance().getApplicationContext())
                    .load(url)
                    .asBitmap()
                    .placeholder(defaultDrawable)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .animate(R.anim.fade_in_image)
                    .into(imageView);
        }
    }

    @BindingAdapter({"imageUrl","placeHolder"})
    public static void loadImage(ImageView imageView, String url, int resId) {
        if (url == null) {
            imageView.setImageResource(R.drawable.ic_default_home_banner);
        } else {
            Glide.with(ExApplication.getInstance().getApplicationContext())
                    .load(url)
                    .asBitmap()
                    .placeholder(resId)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .animate(R.anim.fade_in_image)
                    .into(imageView);
        }
    }

    @BindingAdapter({"imageUrl"})
    public static void loadImage(ImageView imageView, String url) {
        if (url == null) {
            imageView.setImageResource(R.drawable.ic_default_home_banner);
        } else {
            Glide.with(ExApplication.getInstance().getApplicationContext())
                    .load(url)
                    .asBitmap()
                    .placeholder(R.drawable.ic_default_home_banner)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .animate(R.anim.fade_in_image)
                    .into(imageView);
        }
    }
}
